<template>
  <div class="login">
    <div class="form">
      <h1>管理员注册</h1>
      <el-form label-width="80px">
        <el-form-item label="用户名称">
          <el-input v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item label="用户密码">
          <el-input v-model="user.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="reguser">注册</el-button>
          <el-button type="warning" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Reguser',
  data() {
    return {
      user: {
        username: '',
        password: '',
      },
    }
  },
  methods: {
    async reguser() {
      let params = new URLSearchParams()
      params.append('username', this.user.username)
      params.append('password', this.user.password)
      const { data: res } = await this.$http.post('api/reguser', params)
      if (res.status !== 0) return this.$message.error('注册失败！')
      this.$message.success('注册成功！')
      this.$router.push('/login')
    },
    reset() {
      this.user.username = ''
      this.user.password = ''
    },
  },
}
</script>

<style scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 500px;
}
.login h1 {
  text-align: center;
}
</style>
